//
//  XHbluetoolUtils.m
//  HongxuanBluetooth
//
//  Created by 广州弘轩科技发展有限公司 on 2023/8/8.
//

#import "XHbluetoolUtils.h"

@implementation XHbluetoolUtils

+(NSString *)BaseSystem16ToBaseSystem10:(NSString *)str{
    return [NSString stringWithFormat:@"%lu",strtoul(str.UTF8String, 0, 16)];
}
+(NSString *)BaseSystem10ToBaseSystem16:(NSString *)str{
    
    return [NSString stringWithFormat:@"%llx",str.longLongValue];
    
    
//    NSLog(@"16进制转10进制 = %lu",strtoul(@"0b".UTF8String, 0, 16));
//    NSLog(@"16进制转10进制 = %lu",strtoul(@"0104020000b930".UTF8String, 0, 10));
//    NSLog(@"10进制转16进制 = %@",[NSString stringWithFormat:@"%x",@"0104020000b930".longLongValue]);//unsigned
//    NSLog(@"%@",[self getIPAddresses]);
    
}
// 将字符串转为16进制
//+ (NSString *)hexStringFromString:(NSString *)string {
//    NSData *myD = [string dataUsingEncoding:NSUTF8StringEncoding];
////    NSLog(@"%@",myD);
//    Byte *bytes = (Byte *)[myD bytes];
//
//    //下面是Byte 转换为16进制。
//    NSString *hexStr = @"";
//    for(int i = 0; i < [myD length]; i++) {
////        NSLog(@"%x",bytes[i]);
//        NSString *newHexStr = [NSString stringWithFormat:@"%x",bytes[i]&0xff]; //16进制数
//        if([newHexStr length] == 1) {
//            hexStr = [NSString stringWithFormat:@"%@0%@",hexStr,newHexStr];
//        } else {
//            hexStr = [NSString stringWithFormat:@"%@%@",hexStr,newHexStr];
//        }
//    }
//    int num = hexStr.length % 16;
//    if (num == 0) {
//
//    } else {
//        for (int i = 0; i < 16 - num; i++) {
//            hexStr = [NSString stringWithFormat:@"%@F",hexStr];
//        }
//    }
//    return hexStr;
//}

//将NSString转换成十六进制的字符串则可使用如下方式:
//+ (NSString *)convertStringToHexStr:(NSString *)str {
//
//    if (!str || [str length] == 0) {
//
//                 return @"";
//
//             }
//    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
//    NSMutableString *string = [[NSMutableString alloc] initWithCapacity:[data length]];
//    [data enumerateByteRangesUsingBlock:^(const void *bytes, NSRange byteRange, BOOL *stop) {
//        unsigned char *dataBytes = (unsigned char*)bytes;
//        for (NSInteger i = 0; i < byteRange.length; i++) {
//            NSString *hexStr = [NSString stringWithFormat:@"%x", (dataBytes[i]) & 0xff];
//            if ([hexStr length] == 2) {
//                [string appendString:hexStr];
//
//            } else { [string appendFormat:@"0%@", hexStr];
//
//            }
//        }
//
//    }];
//    return string;
//
//}
//将十六进制的字符串转换成NSString则可使用如下方式:
//+ (NSString *)convertHexStrToString:(NSString *)str {
//if (!str || [str length] == 0) {
//    return nil;
//
//}
//    NSMutableData *hexData = [[NSMutableData alloc] initWithCapacity:8];
//    NSRange range; if ([str length] % 2 == 0) {
//        range = NSMakeRange(0, 2);
//
//    } else {
//        range = NSMakeRange(0, 1);
//
//    } for (NSInteger i = range.location; i < [str length]; i += 2) {
//        unsigned int anInt;
//        NSString *hexCharStr = [str substringWithRange:range];
//        NSScanner *scanner = [[NSScanner alloc] initWithString:hexCharStr];
//        [scanner scanHexInt:&anInt];
//        NSData *entity = [[NSData alloc] initWithBytes:&anInt length:1];
//        [hexData appendData:entity];
//        range.location += range.length;
//        range.length = 2;
//
//    }
//    NSString *string = [[NSString alloc]initWithData:hexData encoding:NSUTF8StringEncoding];
//    return string;
//
//}
+ (NSData *)hexToBytes:(NSString *)str{
    
    NSMutableData* data = [NSMutableData data];
    int idx;
    for (idx = 0; idx+2 <= str.length; idx+=2) {
    NSRange range = NSMakeRange(idx, 2);
    NSString* hexStr = [str substringWithRange:range];
    NSScanner* scanner = [NSScanner scannerWithString:hexStr];
    unsigned int intValue;
    [scanner scanHexInt:&intValue];
    [data appendBytes:&intValue length:1];
   }
   return data;
    
    
}
+ (int)intTransitionhex16:(int)time{
    
    if(time == 0){
        time = 0x00;
    }else if (time == 1){
        time = 0x01;
    }else if (time == 2){
        time = 0x02;
    }else if (time == 3){
        time = 0x03;
    }else if (time == 4){
        time = 0x04;
    }else if (time == 5){
        time = 0x05;
    }else if (time == 6){
        time = 0x06;
    }else if (time == 7){
        time = 0x07;
    }else if (time == 8){
        time = 0x08;
    }else if (time == 9){
        time = 0x09;
    }else if (time == 10){
        time = 0x0A;
    }else if (time == 11){
        time = 0x0B;
    }else if (time == 12){
        time = 0x0C;
    }else if (time == 13){
        time = 0x0D;
    }else if (time == 14){
        time = 0x0E;
    }else if (time == 15){
        time = 0x0F;
    }else if (time == 16){
        time = 0x10;
    }else if (time == 17){
        time = 0x11;
    }else if (time == 18){
        time = 0x12;
    }else if (time == 19){
        time = 0x13;
    }else if (time == 20){
        time = 0x14;
    }else if (time == 21){
        time = 0x15;
    }else if (time == 22){
        time = 0x16;
    }else if (time == 23){
        time = 0x17;
    }else if (time == 24){
        time = 0x18;
    }else if (time == 25){
        time = 0x19;
    }else if (time == 26){
        time = 0x1A;
    }else if (time == 27){
        time = 0x1B;
    }else if (time == 28){
        time = 0x1C;
    }else if (time == 29){
        time = 0x1D;
    }else if (time == 30){
        time = 0x1E;
    }else if (time == 31){
        time = 0x1F;
    }else if (time == 32){
        time = 0x20;
    }else if (time == 33){
        time = 0x21;
    }else if (time == 34){
        time = 0x22;
    }else if (time == 35){
        time = 0x23;
    }else if (time == 36){
        time = 0x24;
    }else if (time == 37){
        time = 0x25;
    }else if (time == 38){
        time = 0x26;
    }else if (time == 39){
        time = 0x27;
    }else if (time == 40){
        time = 0x28;
    }else if (time == 41){
        time = 0x29;
    }else if (time == 42){
        time = 0x2A;
    }else if (time == 43){
        time = 0x2B;
    }else if (time == 44){
        time = 0x2C;
    }else if (time == 45){
        time = 0x2D;
    }else if (time == 46){
        time = 0x2E;
    }else if (time == 47){
        time = 0x2F;
    }else if (time == 48){
        time = 0x30;
    }else if (time == 49){
        time = 0x31;
    }else if (time == 50){
        time = 0x32;
    }else if (time == 51){
        time = 0x33;
    }else if (time == 52){
        time = 0x34;
    }else if (time == 53){
        time = 0x35;
    }else if (time == 54){
        time = 0x36;
    }else if (time == 55){
        time = 0x37;
    }else if (time == 56){
        time = 0x38;
    }else if (time == 57){
        time = 0x39;
    }else if (time == 58){
        time = 0x3A;
    }else if (time == 59){
        time = 0x3B;
    }
    return time;
}

+ (int)hexadecimalto10:(NSString *)str{
    int time;
    if([str isEqualToString:@"00"]){
        time = 0;
    }else if ([str isEqualToString:@"01"]){
        time = 1;
    }else if ([str isEqualToString:@"02"]){
        time = 2;
    }else if ([str isEqualToString:@"03"]){
        time = 3;
    }else if ([str isEqualToString:@"04"]){
        time = 4;
    }else if ([str isEqualToString:@"05"]){
        time = 5;
    }else if ([str isEqualToString:@"06"]){
        time = 6;
    }else if ([str isEqualToString:@"07"]){
        time = 7;
    }else if ([str isEqualToString:@"08"]){
        time = 8;
    }else if ([str isEqualToString:@"09"]){
        time = 9;
    }else if ([str isEqualToString:@"0a"]||[str isEqualToString:@"0A"]){
        time = 10;
    }else if ([str isEqualToString:@"0b"]||[str isEqualToString:@"0B"]){
        time = 11;
    }else if ([str isEqualToString:@"0c"]||[str isEqualToString:@"0C"]){
        time = 12;
    }else if ([str isEqualToString:@"0d"]||[str isEqualToString:@"0D"]){
        time = 13;
    }else if ([str isEqualToString:@"0e"]||[str isEqualToString:@"0E"]){
        time = 14;
    }else if ([str isEqualToString:@"0f"]||[str isEqualToString:@"0F"]){
        time = 15;
    }else if ([str isEqualToString:@"10"]){
        time = 16;
    }else if ([str isEqualToString:@"11"]){
        time = 17;
    }else if ([str isEqualToString:@"12"]){
        time = 18;
    }else if ([str isEqualToString:@"13"]){
        time = 19;
    }else if ([str isEqualToString:@"14"]){
        time = 20;
    }else if ([str isEqualToString:@"15"]){
        time = 21;
    }else if ([str isEqualToString:@"16"]){
        time = 22;
    }else if ([str isEqualToString:@"17"]){
        time = 23;
    }else if ([str isEqualToString:@"18"]){
        time = 24;
    }else if ([str isEqualToString:@"19"]){
        time = 25;
    }else if ([str isEqualToString:@"1a"]||[str isEqualToString:@"1A"]){
        time = 26;
    }else if ([str isEqualToString:@"1b"]||[str isEqualToString:@"1B"]){
        time = 27;
    }else if ([str isEqualToString:@"1c"]||[str isEqualToString:@"1C"]){
        time = 28;
    }else if ([str isEqualToString:@"1d"]||[str isEqualToString:@"1D"]){
        time = 29;
    }else if ([str isEqualToString:@"1e"]||[str isEqualToString:@"1E"]){
        time = 30;
    }else if ([str isEqualToString:@"1f"]||[str isEqualToString:@"1F"]){
        time = 31;
    }else if ([str isEqualToString:@"20"]){
        time = 32;
    }else if ([str isEqualToString:@"21"]){
        time = 33;
    }else if ([str isEqualToString:@"22"]){
        time = 34;
    }else if ([str isEqualToString:@"23"]){
        time = 35;
    }else if ([str isEqualToString:@"24"]){
        time = 36;
    }else if ([str isEqualToString:@"25"]){
        time = 37;
    }else if ([str isEqualToString:@"26"]){
        time = 38;
    }else if ([str isEqualToString:@"27"]){
        time = 39;
    }else if ([str isEqualToString:@"28"]){
        time = 40;
    }else if ([str isEqualToString:@"29"]){
        time = 41;
    }else if ([str isEqualToString:@"2a"]||[str isEqualToString:@"2A"]){
        time = 42;
    }else if ([str isEqualToString:@"2b"]||[str isEqualToString:@"2B"]){
        time = 43;
    }else if ([str isEqualToString:@"2c"]||[str isEqualToString:@"2C"]){
        time = 44;
    }else if ([str isEqualToString:@"2d"]||[str isEqualToString:@"2D"]){
        time = 45;
    }else if ([str isEqualToString:@"2e"]||[str isEqualToString:@"2E"]){
        time = 46;
    }else if ([str isEqualToString:@"2f"]||[str isEqualToString:@"2F"]){
        time = 47;
    }else if ([str isEqualToString:@"30"]){
        time = 48;
    }else if ([str isEqualToString:@"31"]){
        time = 49;
    }else if ([str isEqualToString:@"32"]){
        time = 50;
    }else if ([str isEqualToString:@"33"]){
        time = 51;
    }else if ([str isEqualToString:@"34"]){
        time = 52;
    }else if ([str isEqualToString:@"35"]){
        time = 53;
    }else if ([str isEqualToString:@"36"]){
        time = 54;
    }else if ([str isEqualToString:@"37"]){
        time = 55;
    }else if ([str isEqualToString:@"38"]){
        time = 56;
    }else if ([str isEqualToString:@"39"]){
        time = 57;
    }else if ([str isEqualToString:@"3a"]||[str isEqualToString:@"3A"]){
        time = 58;
    }else if ([str isEqualToString:@"3b"]||[str isEqualToString:@"3B"]){
        time = 59;
    }else if ([str isEqualToString:@"3c"]||[str isEqualToString:@"3C"]){
        time = 60;
    }else if ([str isEqualToString:@"3d"]||[str isEqualToString:@"3D"]){
        time = 61;
    }else if ([str isEqualToString:@"3e"]||[str isEqualToString:@"3E"]){
        time = 62;
    }else if ([str isEqualToString:@"3f"]||[str isEqualToString:@"3F"]){
        time = 63;
    }else if ([str isEqualToString:@"40"]){
        time = 64;
    }else if ([str isEqualToString:@"41"]){
        time = 65;
    }else if ([str isEqualToString:@"42"]){
        time = 66;
    }else if ([str isEqualToString:@"43"]){
        time = 67;
    }else if ([str isEqualToString:@"44"]){
        time = 68;
    }else if ([str isEqualToString:@"45"]){
        time = 69;
    }else if ([str isEqualToString:@"46"]){
        time = 70;
    }else if ([str isEqualToString:@"47"]){
        time = 71;
    }else if ([str isEqualToString:@"48"]){
        time = 72;
    }else if ([str isEqualToString:@"49"]){
        time = 73;
    }else if ([str isEqualToString:@"4a"]||[str isEqualToString:@"4A"]){
        time = 74;
    }else if ([str isEqualToString:@"4b"]||[str isEqualToString:@"4B"]){
        time = 75;
    }else if ([str isEqualToString:@"4c"]||[str isEqualToString:@"4C"]){
        time = 76;
    }else if ([str isEqualToString:@"4d"]||[str isEqualToString:@"4D"]){
        time = 77;
    }else if ([str isEqualToString:@"4e"]||[str isEqualToString:@"4E"]){
        time = 78;
    }else if ([str isEqualToString:@"4f"]||[str isEqualToString:@"4F"]){
        time = 79;
    }else if ([str isEqualToString:@"50"]){
        time = 80;
    }else if ([str isEqualToString:@"51"]){
        time = 81;
    }else if ([str isEqualToString:@"52"]){
        time = 82;
    }else if ([str isEqualToString:@"53"]){
        time = 83;
    }else if ([str isEqualToString:@"54"]){
        time = 84;
    }else if ([str isEqualToString:@"55"]){
        time = 85;
    }else if ([str isEqualToString:@"56"]){
        time = 86;
    }else if ([str isEqualToString:@"57"]){
        time = 87;
    }else if ([str isEqualToString:@"58"]){
        time = 88;
    }else if ([str isEqualToString:@"59"]){
        time = 89;
    }else if ([str isEqualToString:@"5a"]||[str isEqualToString:@"5A"]){
        time = 90;
    }else if ([str isEqualToString:@"5b"]||[str isEqualToString:@"5B"]){
        time = 91;
    }else if ([str isEqualToString:@"5c"]||[str isEqualToString:@"5C"]){
        time = 92;
    }else if ([str isEqualToString:@"5d"]||[str isEqualToString:@"5D"]){
        time = 93;
    }else if ([str isEqualToString:@"5e"]||[str isEqualToString:@"5E"]){
        time = 94;
    }else if ([str isEqualToString:@"5f"]||[str isEqualToString:@"5F"]){
        time = 95;
    }else if ([str isEqualToString:@"60"]){
        time = 96;
    }else if ([str isEqualToString:@"61"]){
        time = 97;
    }else if ([str isEqualToString:@"62"]){
        time = 98;
    }else if ([str isEqualToString:@"63"]){
        time = 99;
    }else if ([str isEqualToString:@"64"]){
        time = 100;
    }
    return time;
}
//- (NSData*)ad_hexStringToData {
//    if (self.length % 2 != 0) {
//        return nil;
//    }
//    NSMutableData *mulData = [[NSMutableData alloc] init];
//    for (NSInteger i = 0; i < self.length; i += 2) {
//        NSString *hexChar = [self substringWithRange:NSMakeRange(i, 2)];
//        NSScanner *scanner = [[NSScanner alloc] initWithString:hexChar];
//        unsigned int anInt;
//        [scanner scanHexInt:&anInt];
//        NSData *data = [[NSData alloc] initWithBytes:&anInt length:1];
//        [mulData appendData:data];
//    }
//    return mulData;
//}

#pragma mark 注意！ 上架前必弄，修改好时间，上架后显示正常
+ (BOOL)beginurl
{
    BOOL _isopen;
    NSDate* date = [NSDate date];
    NSCalendar* cal = [NSCalendar currentCalendar];
    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents* d = [cal components:unitFlags fromDate:date];
    NSInteger year = [d year];
    NSInteger month = [d month];
    NSInteger day = [d day];
    NSLog(@"year :%ld month:%ld  day:%ld",year,month,day);
    NSInteger yearsetting = 2023;
    NSInteger monthsetting = 10;
    NSInteger daysetting = 5;

    if (year < yearsetting) {
        _isopen = NO;
    } else if (year > yearsetting) {
        _isopen = YES;
    } else {
        if (month < monthsetting) {
            _isopen = NO;
        } else if (month > monthsetting) {
            _isopen = YES;
        } else {
            if (day < daysetting) {
                _isopen = NO;
            } else {
                _isopen = YES;
            }
        }
    }
    return _isopen;
}
@end
